import random

gold = 5000
key = random.randint(1,9)
while True:
    if gold <= 0:
        print("金钱消耗空了，你失败了")
        break
    print("金钱:",end='')
    print(gold)
    user_key = int(input("请输入你想要猜想的数字:"))

    if user_key == key:
        print("你猜对了")
        gold = gold + 3000
        chios = input("你猜对了，请问你选择继续游戏吗，输入1继续游戏，其他则退出")
        if chios != '1':
            break
    elif user_key > key:
        print("猜大了")
        gold = gold -300
    else:
        print("猜小了")
        gold = gold - 300
print(key)